/*
 * Copyright (c) 2010. raoqn
 */

package com.yfeng.goodjuhome.model;

import com.yfeng.common.dao.IDao;
import com.yfeng.common.dao.Param;
import com.yfeng.exception.ModelException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * www.goodjuhome.com
 * Created by IntelliJ IDEA.
 * User: rqn
 * Date: 2010-8-14
 * Time: 14:04:49
 */
@Component
public class News{
        private static final Log log = LogFactory.getLog(News.class);

    @Autowired
    public IDao baseDao;

    String id, uid, type, title, sort, content, is_top_news, readcount, source, is_recommend, cover;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getIs_top_news() {
        return is_top_news;
    }

    public void setIs_top_news(String is_top_news) {
        this.is_top_news = is_top_news;
    }

    public String getReadcount() {
        return readcount;
    }

    public void setReadcount(String readcount) {
        this.readcount = readcount;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getIs_recommend() {
        return is_recommend;
    }

    public void setIs_recommend(String is_recommend) {
        this.is_recommend = is_recommend;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public boolean isExist(String title) throws ModelException {
        try {
            int ret = baseDao.getRowCount("from news where title=:title", new Param("title", title));
            if (ret > 0)
                return true;
            else
                return false;
        }
        catch (Exception e) {
          log.error(e.getMessage(),e);
            throw new ModelException(e.getMessage(),e);
        }

    }

    @Override
    public String toString() {
        return "News{" +
                "id='" + id + '\'' +
                ", uid='" + uid + '\'' +
                ", type='" + type + '\'' +
                ", title='" + title + '\'' +
                ", sort='" + sort + '\'' +
                ", content='" + content + '\'' +
                ", is_top_news='" + is_top_news + '\'' +
                ", readcount='" + readcount + '\'' +
                ", source='" + source + '\'' +
                ", is_recommend='" + is_recommend + '\'' +
                ", cover='" + cover + '\'' +
                '}';
    }
}
